package qldc.pm.qlktcsdldc.service.persistence;

import java.util.List;

import qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh;
import qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganhImpl;
import qldc.pm.qlktcsdldc.utils.FLog;

import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.util.dao.orm.CustomSQLUtil;

public class DanhMucSoBanNganhFinderImpl extends BasePersistenceImpl<DanhMucSoBanNganh> implements DanhMucSoBanNganhFinder{
	private static final String SEARCHBYTENSOBANNGANH = DanhMucSoBanNganhFinderImpl.class.getName() + ".searchByTenSoBanNganh";
	private static final String SEARCHALL = DanhMucSoBanNganhFinderImpl.class.getName() + ".searchAll";

	
	@SuppressWarnings("unchecked")
	public List<DanhMucSoBanNganh> searchByTenSoBanNganh( String tenSoBanNganh)throws SystemException {
		FLog.Log("searchByTenSoBanNganh :" + tenSoBanNganh );
		
		Session session = null;
		try {
			session = openSession();
			String sql = CustomSQLUtil.get(SEARCHBYTENSOBANNGANH);
		
			FLog.Log("searchByTenSoBanNganh sql:"+sql);
			
			SQLQuery q = session.createSQLQuery(sql);

			q.addEntity("QLKT_DanhMucSoBanNganh", DanhMucSoBanNganhImpl.class);
			QueryPos qpos = QueryPos.getInstance(q);
			qpos.add(StringPool.PERCENT + tenSoBanNganh + StringPool.PERCENT);
			
			return (List<DanhMucSoBanNganh>) QueryUtil.list(q, getDialect(), -1, -1);

		}
		catch (Exception e) {
			throw new SystemException(e);
		}
		finally {
			if (Validator.isNotNull(session)) {
				closeSession(session);
			}
		}
	}
	@SuppressWarnings("unchecked")
	public List<DanhMucSoBanNganh> searchAll()throws SystemException {
		
		Session session = null;
		try {
			session = openSession();
			String sql = CustomSQLUtil.get(SEARCHALL);

			FLog.Log("searchAll sql:"+sql);
			
			SQLQuery q = session.createSQLQuery(sql);

			q.addEntity("QLKT_DanhMucSoBanNganh", DanhMucSoBanNganhImpl.class);
	
			return (List<DanhMucSoBanNganh>) QueryUtil.list(q, getDialect(), -1, -1);

		}
		catch (Exception e) {
			throw new SystemException(e);
		}
		finally {
			if (Validator.isNotNull(session)) {
				closeSession(session);
			}
		}
	}
	
}
